<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
    <link rel="stylesheet" href="plug/mui/css/app.css">
    <link rel="stylesheet" href="./plug/mui/css/mui.min.css">
    <link rel="stylesheet" href="plug/mui/css/mui.picker.min.css">
		<link rel="stylesheet" href="css/net.css">
	</head>
	<body>
		<div class="box">
			<div class="set">
			    <img src="./img/set.png" alt="设置">
			</div>
			<i><img src="./img/network.jpg" alt=""></i> 
			<p>网络不佳,确认是否连接Automation_AGV,点击重新加载</p>
			<h2></h2>
		</div>
	</body>
</html>
<script src="./plug/jquery.min.js"></script>
<script src="plug/mui/js/mui.min.js"></script>
<script src="js/muiLoading.js"></script>
<script src="plug/mui/js/mui.picker.min.js"></script>
<script>
	$(document).ready(function(){
		// ip
	 	let ipValue = localStorage.getItem('ipValue') || "127.0.0.1";
		$('.set').click(function (){
		    mui.prompt('ip', '请输入ip', '提示', ['取消', '确定'], function (e) {
		        if (e.index == 1) {
		            let val = e.value.trim()
		            let flag = isValidIP(val)
		            if (!flag) {
		                mui.toast('请输入正确的IP地址')
		                return false
		            }
		            ipValue = val
		            localStorage.setItem('ipValue', val);
		        }
		    }, 'div')
		    //输入框失去焦点
		    document.querySelector('.mui-popup-input').firstChild.blur()
		    //默认值设置
		    document.querySelector('.mui-popup-input').firstChild.value = ipValue
		})
		function isValidIP(ip) {
		    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
		    return reg.test(ip);
		}
		$('p').click(function(){
			mui.toast("网络测试中..", "div");
			$.ajax({
				url: `http://${ipValue}:55200/v1/network/ping`,
				contentType: "multipart/form-data",
				data: '',
				type: "get",
				dataType: "json",
				timeout: 3000,
				success: (res) => {
					if (res.code == 200) {
						window.location.href ='index.html'
					
					} else {
						 mui.toast('网络错误，请检查是否链接Automation_AGV',{ duration:'long', type:'div' }) 
					}
				},
				error: function() {
					//查看错误信息
					// err()
					// netLess()
					 mui.toast('网络错误，请检查是否链接Automation_AGV',{ duration:'long', type:'div' }) 
				}
			})
			// mui.hideLoading(); 
		})
	})
</script>